POI 导入导出时异常[java.io.IOException: Broken pipe]

使用用POI导出文件时抛出异常java.io.IOException: Broken pipe

ERROR:  'java.io.IOException: Broken pipe'
org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save: an error occurs while saving the package : The part /docProps/core.xml fail to be saved in the stream with marshaller org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller@783e76d

原因:输入流,输出流在使用之后(输入流用于构造函数,输出流用于写入数据),再使用同样的流做之前的事会报错(再使用输入流报错流为空,再使用输出流报错为 org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save: an error occurs while saving the package : The part /docProps/app.xml failed to be saved in the stream with marshaller org.apache.poi.openxml4j.opc.internal.marshallers.DefaultMarshaller@4bbfb90a)。所以对于同一个引用的流,在使用之后还想要继续使用的话,必须重新新建一个流对象

 

记得使用只用及时关闭 流。为了避免在特殊情况下导致流关闭失败,应该吧关闭流的操作放在finally代码块中

}finally {
            inputStream.close();
            ouputStream.close();
            workbook.close();
}

 

posted @ 2018-09-06 15:27  隔壁w王叔叔  阅读(10291)  评论(0编辑  收藏  举报